home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 19.7 KB | 614 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UPrintHandler.cp
- // Copyright © 1985-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __UPRINTHANDLER__
- #include "UPrintHandler.h"
- #endif
-
- // MacApp
-
- #ifndef __UFAILURE__
- #include "UFailure.h"
- #endif
-
- #ifndef __UGEOMETRY__
- #include "UGeometry.h"
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UPATCH__
- #include "UPatch.h"
- #endif
-
- #ifndef __UVIEW__
- #include "UView.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- // Toolbox
-
- #ifndef __BALLOONS__
- #include <Balloons.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- // ANSI
-
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
-
- //========================================================================================
- // static data members
- //========================================================================================
- Boolean TPrintHandler::gFinderPrintingProceed; // proceed with Finder printing
- Boolean TPrintHandler::gCouldPrint;
- VPoint TPrintHandler::gPageOffset;
- TPrintHandler* TPrintHandler::gNullPrintHandler;
- TPrintHandler* TPrintHandler::gPrintHandler;
- TPrintHandler* TPrintHandler::gCurrPrintHandler;
-
-
- //========================================================================================
- // CLASS TPrintMenuBehavior
- //========================================================================================
- #undef Inherited
- #define Inherited TBehavior
-
- #pragma segment PrintOpen
- MA_DEFINE_CLASS_M1(TPrintMenuBehavior, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TPrintMenuBehavior constructor
- //----------------------------------------------------------------------------------------
- #pragma segment PrintOpen
-
- TPrintMenuBehavior::TPrintMenuBehavior()
- {
- fPrintHandler = NULL;
- } // TPrintMenuBehavior::TPrintMenuBehavior
-
- //----------------------------------------------------------------------------------------
- // TPrintMenuBehavior destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TPrintMenuBehavior::~TPrintMenuBehavior()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintMenuBehavior::IPrintMenuBehavior:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintOpen
-
- void TPrintMenuBehavior::IPrintMenuBehavior(TPrintHandler* itsPrintHandler)
- {
- this->IBehavior(kPrintMenuBehaviorID);
-
- itsPrintHandler->SetManager(this);
- fPrintHandler = itsPrintHandler;
- } // TPrintMenuBehavior::IPrintMenuBehavior
-
- //----------------------------------------------------------------------------------------
- // TPrintMenuBehavior::DoScriptCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- Boolean TPrintMenuBehavior::DoScriptCommand(CommandNumber aCommandNumber,
- TAppleEvent* messageEvent,
- TAppleEvent* replyEvent)
- {
- Boolean wasHandled = FALSE;
-
- if (fPrintHandler)
- {
- wasHandled = fPrintHandler->DoScriptCommand(aCommandNumber, messageEvent, replyEvent);
- // Note: DoScriptCommand is implemented in TStdPrintHandler, not TPrintHandler.
- }
-
- if (!wasHandled)
- wasHandled = Inherited::DoScriptCommand(aCommandNumber, messageEvent, replyEvent);
-
- return wasHandled;
- } // TPrintMenuBehavior::DoScriptCommand
-
- //----------------------------------------------------------------------------------------
- // TPrintMenuBehavior::DoMenuCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TPrintMenuBehavior::DoMenuCommand(CommandNumber aCommandNumber)
- {
- // Can print if:
- // • have a print handler, and
- // • print handler has a view, and
- // either • view is not shown (e.g., Finder printing), or
- // • view is active.
- // • we are printing from the finder
- // NOTE: we don't support printing of view's that are shown, but not active.
-
- // This algorithm allows a document to arbitrate between its various
- // TPrintMenuBehavior objects, representing several printable views owned by the
- // document. This arbitration wasn't supported in MacApp prior to version 3.0.
-
- if (fPrintHandler && fPrintHandler->fView && (!fPrintHandler->fView->IsShown() || fPrintHandler->fView->IsActive() || TPrintHandler::gFinderPrintingProceed))
- {
- if (!fPrintHandler->DoPrintCommand(aCommandNumber)) // if we didn't print, call Inherited
- Inherited::DoMenuCommand(aCommandNumber);
- }
- else
- Inherited::DoMenuCommand(aCommandNumber);
- } // TPrintMenuBehavior::DoMenuCommand
-
- //----------------------------------------------------------------------------------------
- // TPrintMenuBehavior::DoSetupMenus:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- void TPrintMenuBehavior::DoSetupMenus()
- {
- Inherited::DoSetupMenus();
-
- // see note in TPrintMenuBehavior::DoMenuCommand
- if (fPrintHandler && fPrintHandler->fView && fPrintHandler->fView->IsActive())
- fPrintHandler->DoSetupPrintMenus();
- } // TPrintMenuBehavior::DoSetupMenus
-
-
- //========================================================================================
- // CLASS TPrintHandler
- //========================================================================================
- #undef Inherited
- #define Inherited TBehavior
-
- #pragma segment PrintOpen
- MA_DEFINE_CLASS_M1(TPrintHandler, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler constructor
- //----------------------------------------------------------------------------------------
- #pragma segment PrintOpen
-
- TPrintHandler::TPrintHandler()
- {
- fView = NULL;
- fDocument = NULL;
- fManager = NULL;
- fFocusedPage = 1;
- fShowBreaks = FALSE;
-
- fViewPerPage = gZeroVPt;
- fDeviceRes = CPoint(72, 72); // default matches QD default
- } // TPrintHandler::TPrintHandler
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TPrintHandler::~TPrintHandler()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::IPrintHandler:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintOpen
-
- void TPrintHandler::IPrintHandler(TView* itsView)
- {
- this->IBehavior(kPrintBehaviorID); // attaching to the view is handled by
- // AttachPrintHandler
- fView = itsView;
- } // TPrintHandler::IPrintHandler
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::GetViewPerPage:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- VPoint TPrintHandler::GetViewPerPage()
- {
- return fViewPerPage;
- } // TPrintHandler::GetViewPerPage
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::GetDeviceRes:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
-
- CPoint TPrintHandler::GetDeviceRes()
- {
- return fDeviceRes;
- } // TPrintHandler::GetDeviceRes
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::BreakFollowing:
- //----------------------------------------------------------------------------------------
- #pragma segment MANever
-
- VCoordinate TPrintHandler::BreakFollowing(VHSelect/* vhs */,
- VCoordinate/* previousBreak */,
- Boolean&/* automatic */ )
-
- {
- #if qDebug
- ProgramBreak("BreakFollowing called for non-subclassed Printhandler");
- #endif
-
- return 0;
- } // TPrintHandler::BreakFollowing
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::CalcPageStrips:
- //----------------------------------------------------------------------------------------
- #pragma segment MANever
-
- VPoint TPrintHandler::CalcPageStrips()
- {
- #if qDebug
- ProgramBreak("CalcPageStrips called for non-subclassed Printhandler");
- #endif
- return gZeroVPt;
- } // TPrintHandler::CalcPageStrips
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::CalcViewPerPage:
- //----------------------------------------------------------------------------------------
- #pragma segment MANever
-
- VPoint TPrintHandler::CalcViewPerPage()
- {
- #if qDebug
- ProgramBreak("CalcViewPerPage called for non-subclassed Printhandler");
- #endif
- return gZeroVPt;
- } // TPrintHandler::CalcViewPerPage
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::Invalidate:
- //----------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- void TPrintHandler::Invalidate()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::Validate:
- //----------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- void TPrintHandler::Update()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::DrawPrintFeedback:
- //----------------------------------------------------------------------------------------
- #pragma segment MAPrintingRes
-
- //Draw page-breaks, page-numbers, etc.
- void TPrintHandler::DrawPrintFeedback(const VRect& /* area */)
- {
- } // TPrintHandler::DrawPrintFeedback
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::DrawPageBreak:
- //----------------------------------------------------------------------------------------
- #pragma segment MAPrintingRes
-
- void TPrintHandler::DrawPageBreak(VHSelect /* vhs */,
- long /* whichBreak */,
- VCoordinate /* loc */,
- Boolean /* automatic */)
- {
- } // TPrintHandler::DrawPageBreak
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::Focus:
- //----------------------------------------------------------------------------------------
- #pragma segment MAPrintingRes
-
- Boolean TPrintHandler::Focus()
- {
- return FALSE;
- } // TPrintHandler::Focus
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::FocusOnInterior:
- //----------------------------------------------------------------------------------------
- #pragma segment MAPrintingRes
-
- void TPrintHandler::FocusOnInterior()
- {
- } // TPrintHandler::FocusOnInterior
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::GetQDOrigin:
- //----------------------------------------------------------------------------------------
- #pragma segment MAPrintingRes
-
- CPoint TPrintHandler::GetQDOrigin()
- {
- return gZeroPt;
- } // TPrintHandler::GetQDOrigin
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::GetViewToQDOffset:
- //----------------------------------------------------------------------------------------
- #pragma segment MAPrintingRes
-
- VPoint TPrintHandler::GetViewToQDOffset()
- {
- return gZeroVPt;
- } // TPrintHandler::GetViewToQDOffset
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::GetPrintInfo:
- //----------------------------------------------------------------------------------------
- #pragma segment MAPrintingRes
-
- TPrintInfo* TPrintHandler::GetPrintInfo()
- {
- return NULL;
- } // TPrintHandler::GetPrintInfo
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::LocatePageInterior:
- //----------------------------------------------------------------------------------------
- #pragma segment MANever
-
- VPoint TPrintHandler::LocatePageInterior(long /* pageNumber */)
- {
- return gZeroVPt;
- } // TPrintHandler::LocatePageInterior
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::MaxPageNumber:
- //----------------------------------------------------------------------------------------
- #pragma segment MANever
-
- long TPrintHandler::MaxPageNumber()
- {
- return 0;
- } // TPrintHandler::MaxPageNumber
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::Print:
- //----------------------------------------------------------------------------------------
- #pragma segment MAPrint
-
- Boolean TPrintHandler::Print(CommandNumber /* itsCommandNumber */)
- {
- return TRUE;
- } // TPrintHandler::Print
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::PrinterChanged:
- //----------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- void TPrintHandler::PrinterChanged()
-
- {
- } // TPrintHandler::PrinterChanged
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::SetupForFinder:
- //----------------------------------------------------------------------------------------
- #pragma segment MAFinder
-
- Boolean TPrintHandler::SetupForFinder(CommandNumber /* aCommandNumber */)
- {
- #if qDebugMsg
- fprintf(stderr, "SetupForFinder called for a view that can't\n");
- #endif
-
- return FALSE;
- } // TPrintHandler::SetupForFinder
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::RedoPageBreaks:
- //----------------------------------------------------------------------------------------
- #pragma segment MANever
-
- void TPrintHandler::RedoPageBreaks()
- {
- } // TPrintHandler::RedoPageBreaks
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::Reset:
- //----------------------------------------------------------------------------------------
- #pragma segment MANever
-
- void TPrintHandler::Reset()
- {
- } // TPrintHandler::Reset
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::DoPrintCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MANever
-
- Boolean TPrintHandler::DoPrintCommand(CommandNumber /* aCommandNumber */)
- {
- return FALSE;
- } // TPrintHandler::DoPrintCommand
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::DoSetupPrintMenus:
- //----------------------------------------------------------------------------------------
- #pragma segment MANever
-
- void TPrintHandler::DoSetupPrintMenus()
- {
- } // TPrintHandler::DoSetupPrintMenus
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::SetDefaultPrintInfo:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintOpen
-
- // Meant to be overridden in a subclass that really prints
- void TPrintHandler::SetDefaultPrintInfo()
- {
- } // TPrintHandler::SetDefaultPrintInfo
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::SetPageInterior:
- //----------------------------------------------------------------------------------------
- #pragma segment MANever
-
- void TPrintHandler::SetPageInterior(long /* pageNumber */)
- {
- } // TPrintHandler::SetPageInterior
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::SetPageOffset:
- //----------------------------------------------------------------------------------------
- #pragma segment MANever
-
- void TPrintHandler::SetPageOffset(const VPoint& /* coord */)
- {
- } // TPrintHandler::SetPageOffset
-
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::GetManager:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintOpen
-
- TPrintMenuBehavior* TPrintHandler::GetManager()
- {
- return fManager;
- } // TPrintHandler::GetManager
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::SetManager:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintOpen
-
- void TPrintHandler::SetManager(TPrintMenuBehavior* itsManager)
- {
- fManager = itsManager;
- } // TPrintHandler::SetManager
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::SetOwner
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TPrintHandler::SetOwner(TEventHandler* itsOwner) // override
- {
- Inherited::SetOwner(itsOwner);
-
- if (fView)
- {
- TWindow* window = fView->GetWindow();
- if (window)
- {
- if (itsOwner)
- {
- if (itsOwner == fView)
- window->SetScriptingPrintHandler(this);
- #if qDebug
- else
- ProgramBreak("Print handler owner != fView");
- #endif
- }
- else
- {
- window->ReleaseScriptingPrintHandler(this);
- // Note: This does not get called when a window is closed
- // because the window goes away first.
- }
- }
- }
- } // TPrintHandler::SetOwner
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::TerminateUPrinting:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
- void TPrintHandler::TerminateUPrinting()
- {
- // Thank you
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::PrepareForFinderPrinting:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
- void TPrintHandler::PrepareForFinderPrinting(const FSSpec* /* targetPrinter */)
- {
- // Thank you
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::DispatcherIsAvailable:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
- void TPrintHandler::DispatcherIsAvailable()
- {
- // Thank you
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::GetSavePrintInfoSize:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
- long TPrintHandler::GetSavePrintInfoSize(TPrintInfo* /* itsPrintInfo */, TFile* /* itsFile */, Boolean /* useRsrcFork */)
- {
- // Thank you
- return 0;
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::SavePrintInfo:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
- void TPrintHandler::SavePrintInfo(TPrintInfo* /* itsPrintInfo */, TFile* /* itsFile */, Boolean /* useRsrcFork */)
- {
- // Thank you
- }
-
- //----------------------------------------------------------------------------------------
- // TPrintHandler::RestorePrintInfo:
- //----------------------------------------------------------------------------------------
- #pragma segment PrintRes
- TPrintInfo* TPrintHandler::RestorePrintInfo(TFile* /* itsFile */, Boolean /* useRsrcFork */)
- {
- // Thank you
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // End of UPrintHandler.cp
-
- #pragma segment Inline
-